#!/usr/bin/env python
# coding:utf-8
import xadmin
from app01 import models
from xadmin import views


class GlobalSetting(object):
    site_title = "蒋文辉xadmin后台管理系统"
    site_footer = "http://blog.51cto.com/9272317"


xadmin.site.register(views.CommAdminView, GlobalSetting)

# xadmin.site.register(models.userpro)
#
#
# class The_number_of_clicks_Admin(object):
#     list_display = ['province_name', 'number', 'updatetime']
#     search_fields = ['province_name', 'number', ]
#     list_filter = ['province_name', 'number', 'updatetime']
#
#
# class source_ip_Admin(object):
#     list_display = ['province_name', 'number', 'updatetime']
#     search_fields = ['province_name', 'number', ]
#     list_filter = ['province_name', 'number', 'updatetime']
#
#
# xadmin.site.register(models.The_number_of_clicks, The_number_of_clicks_Admin)
# xadmin.site.register(models.source_ip, source_ip_Admin)


table_list = ['The_number_of_clicks', 'source_ip', 'Business_daily_traffic', 'real', 'City_trading_volume', 'subclass',
              'uv_real_time', 'user_num', 'zcpvuv', 'jia_subclass', 'Jiaywpv', 'Commodity_categories',
              'Commodity_subclass', 'userpro', 'business_real_time_access', 'provinces_rmb', 'categories', 'guojia',
              'city', 'qu']
demo = ''
for i in table_list:
    demo += '''
try:
    class %s_admin(object):
        list_display = list(models.%s.objects.all()[0].__dict__.keys())
        for li in list_display:
            if "_id"  in li or "id"  in li:
                list_display.remove(li)
        list_display.remove('_state')
    xadmin.site.register(models.%s, %s_admin)
except Exception as e:
    xadmin.site.register(models.%s, )
    print(e,)
    ''' % (i, i, i, i, i)
# print(demo)
exec(demo)
